/*
 * @(#)DrawTest.java 1.0 05/03/16
 *
 * You can modify the template of this file in the
 * directory ..\JCreator\Templates\Template_1\Project_Name.java
 *
 * You can also create your own project template by making a new
 * folder in the directory ..\JCreator\Template\. Use the other
 * templates as examples.
 *
 */

package gui;

import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


class AwtChoicePanel extends Panel {
	Choice c = new Choice();
	Label l = new Label("pls choose font:");
	String fntName = "Arial";

	AwtChoicePanel() {
		add(l);
		add(c);
		GraphicsEnvironment env = GraphicsEnvironment
				.getLocalGraphicsEnvironment();
		String fontNames[] = env.getAvailableFontFamilyNames();
		for (int i = 0; i < fontNames.length; i++)
			c.addItem(fontNames[i]);
		c.addItemListener(new MyItemListener());
	}

	private class MyItemListener implements ItemListener {

		public void itemStateChanged(ItemEvent ie) {
			fntName = c.getSelectedItem();
			repaint();
			// l.setFont(new Font(fntName , Font.BOLD, 20));
			// l.repaint();
		}
	}

	public void paint(Graphics g) {
		g.setFont(new Font(fntName, Font.BOLD, 20));
		g.drawString("Hello World!", 100, 100);

	}
}

public class AwtDrawTest extends Frame {

	public AwtDrawTest() {
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				dispose();
				System.exit(0);
			}
		});
	}

	public static void main(String args[]) {
		System.out.println("Starting DrawTest...");
		AwtDrawTest mainFrame = new AwtDrawTest();
		mainFrame.add(new AwtChoicePanel());
		mainFrame.setSize(400, 400);
		mainFrame.setTitle("DrawTest");
		mainFrame.setVisible(true);
	}
}
